a = int(input())
k = 0
lst = []
a4 = a % 10
a3 = a % 100 // 10
a2 = a % 1000 // 100
a1 = a // 1000
b3 = a % 100
b2 = a % 1000 // 10
b1 = a // 100
c1 = a // 10
c2 = a % 1000


def check(n):
    q=0
    for i in range(2, n // 2+1):
            if n%i==0:
                q=q+1
    if q==0:
        lst.append(n)
    else:
        q=0

check(a1)
check(a2)
check(a3)
check(a4)
check(b1)
check(b2)
check(b3)
check(c1)
check(c2)
check(a)

if not lst:
    print(0)
elif lst:
    max_number = max(lst)
    print(max_number)